<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title th:text="${type == 'weekly' ? '本周热播' : (type == 'monthly' ? '本月热播' : (type == 'rating' ? '评分排行' : '总播放排行'))} + ' - 电影网站'"></title>
    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <link rel="stylesheet" href="/css/style.css">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
    <div class="container">
        <a class="navbar-brand" href="/">电影网站</a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav me-auto">
                <li class="nav-item">
                    <a class="nav-link" th:classappend="${type == 'weekly' ? 'active' : ''}" href="/movie/ranking/weekly">周榜</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" th:classappend="${type == 'monthly' ? 'active' : ''}" href="/movie/ranking/monthly">月榜</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" th:classappend="${type == 'all' ? 'active' : ''}" href="/movie/ranking/all">总榜</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" th:classappend="${type == 'rating' ? 'active' : ''}" href="/movie/ranking/rating">评分榜</a>
                </li>
            </ul>
            <ul class="navbar-nav">
                <li class="nav-item" th:if="${session.user == null}">
                    <a class="nav-link" href="/login">登录</a>
                </li>
                <li class="nav-item dropdown" th:if="${session.user != null}">
                    <a class="nav-link dropdown-toggle" href="#" data-bs-toggle="dropdown">
                        <span th:text="${session.user.username}"></span>
                        <span class="badge bg-warning" th:if="${session.user.isVip}">VIP</span>
                    </a>
                    <ul class="dropdown-menu">
                        <li><a class="dropdown-item" href="/order/vip" th:if="${!session.user.isVip}">开通VIP</a></li>
                        <li><a class="dropdown-item" href="/admin" th:if="${session.user.isAdmin}">后台管理</a></li>
                        <li><hr class="dropdown-divider"></li>
                        <li><a class="dropdown-item" href="/logout">退出登录</a></li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
</nav>

<div class="container mt-4">
    <div class="row">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">
                    <h5 class="card-title mb-0" th:text="${type == 'weekly' ? '本周热播' : (type == 'monthly' ? '本月热播' : (type == 'rating' ? '评分排行' : '总播放排行'))}"></h5>
                </div>
                <div class="list-group list-group-flush ranking-list">
                    <div class="list-group-item" th:each="movie, stat : ${movies}">
                        <div class="row align-items-center">
                            <div class="col-auto">
                                <span class="h4 mb-0" th:text="${stat.count}"></span>
                            </div>
                            <div class="col-auto">
                                <img th:src="${movie.coverUrl}" alt="电影封面" style="width: 100px; height: 150px; object-fit: cover;">
                            </div>
                            <div class="col">
                                <h5 class="mb-1">
                                    <a th:href="@{'/movie/' + ${movie.id}}" class="text-decoration-none" th:text="${movie.name}"></a>
                                    <span class="badge bg-warning ms-2" th:if="${movie.isVip}">VIP</span>
                                </h5>
                                <p class="mb-1">
                                    <span th:each="category : ${movie.categories}" class="badge bg-primary me-2" th:text="${category}"></span>
                                    <span class="badge bg-success me-2" th:text="'评分: ' + ${movie.score}"></span>
                                    <span class="text-muted" th:text="'播放: ' + ${movie.playCount}"></span>
                                </p>
                                <p class="mb-1 text-muted" th:text="${movie.description}"></p>
                                <small class="text-muted">
                                    导演：
                                    <span th:each="director, iterStat : ${movie.directors}">
                                        <a th:href="@{'/movie/director/' + ${director.id}}" class="text-decoration-none" th:text="${director.name}"></a>
                                        <span th:if="${!iterStat.last}">, </span>
                                    </span>
                                    &nbsp;|&nbsp;
                                    主演：
                                    <span th:each="actor, iterStat : ${movie.actors}">
                                        <a th:href="@{'/movie/actor/' + ${actor.id}}" class="text-decoration-none" th:text="${actor.name}"></a>
                                        <span th:if="${!iterStat.last}">, </span>
                                    </span>
                                </small>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-md-4">
            <!-- 其他排行榜快速入口 -->
            <div class="card mb-4" th:if="${type != 'weekly'}">
                <div class="card-header">本周热播</div>
                <div class="list-group list-group-flush">
                    <a th:each="m : ${weeklyRanking}" th:href="@{'/movie/' + ${m.id}}"
                       class="list-group-item list-group-item-action d-flex justify-content-between align-items-center">
                        <span th:text="${m.name}"></span>
                        <span class="badge bg-primary rounded-pill" th:text="${m.playCount}"></span>
                    </a>
                </div>
            </div>

            <div class="card mb-4" th:if="${type != 'monthly'}">
                <div class="card-header">本月热播</div>
                <div class="list-group list-group-flush">
                    <a th:each="m : ${monthlyRanking}" th:href="@{'/movie/' + ${m.id}}"
                       class="list-group-item list-group-item-action d-flex justify-content-between align-items-center">
                        <span th:text="${m.name}"></span>
                        <span class="badge bg-primary rounded-pill" th:text="${m.playCount}"></span>
                    </a>
                </div>
            </div>

            <div class="card" th:if="${type != 'rating'}">
                <div class="card-header">高分推荐</div>
                <div class="list-group list-group-flush">
                    <a th:each="m : ${ratingRanking}" th:href="@{'/movie/' + ${m.id}}"
                       class="list-group-item list-group-item-action d-flex justify-content-between align-items-center">
                        <span th:text="${m.name}"></span>
                        <span class="badge bg-success rounded-pill" th:text="${m.score}"></span>
                    </a>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="/js/jquery.min.js"></script>
<script src="/js/bootstrap.bundle.min.js"></script>
</body>
</html>